package com.smart.wap.app;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.BaseSearch;
import com.smart.common.entities.core.Page;
import com.smart.manager.pop.entities.models.PopC2cAttend;
import com.smart.manager.pop.entities.models.PopC2cRecord;
import com.smart.manager.pop.repository.ActivityAttendRepository;
import com.smart.manager.pop.repository.ActivityRecordRepository;
import com.smart.service.remind.RemindService;
import com.smart.utils.MemberAcl;
import com.smart.utils.MemberStp;
import com.smart.wap.bodys.SharePigResult;
import com.smart.wap.service.BindInviterService;
import com.smart.wap.service.ShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author Administrator
 */

@Api(tags = "移动端-分享接口")
@RestController
@RequestMapping(SmartConstant.WAP_API_PREFIX + "im")
@RequiredArgsConstructor
public class ShareController {
    private final ActivityAttendRepository attendRepository;
    private final ShareService shareService;
    private final ActivityRecordRepository recordRepository;
    private final RemindService remindService;
    private final  BindInviterService bindInviterService;





    @ApiOperation(value = "获取邀请记录")
    @GetMapping(value = "getShareList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Page<PopC2cRecord>> getShareList(@Validated BaseSearch baseSearch) {
        Page<PopC2cRecord> result = recordRepository.getMyRecordList(MemberAcl.getLoginId(), baseSearch);
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "获取会员分享信息")
    @GetMapping(value = "getShareInfo")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<PopC2cAttend> getMemberSharePoster() {
        PopC2cAttend result = attendRepository.getMemberSharePoster();
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "根据猪猪代码获取分享信息")
    @GetMapping(value = "getPigDetailShare/{pigCode}")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<PopC2cAttend> getPigDetailShare(@PathVariable String pigCode) {
        PopC2cAttend result = attendRepository.getPigSharePoster(pigCode, MemberAcl.getLoginId());
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "获取分享猪仔")
    @GetMapping(value = "getSharePig/{code}")
    public AjaxResult<SharePigResult> getSharePig(@PathVariable String code) {
        SharePigResult sharePig = shareService.getSharePig(code);
        return AjaxResult.data(sharePig);
    }



    @ApiOperation(value = "测试小程序推送")
    @GetMapping(value = "sendMiniProgramsMsg/{openId}/{msg}/{msg1}")
    public AjaxResult<String> sendMiniProgramsMsg(@PathVariable String openId, @PathVariable String msg, @PathVariable String msg1) {
        remindService.sendMiniProgramsMsg(openId, msg1, msg, false);
        return AjaxResult.success();
    }


}
